#include <SFML/Graphics.hpp>
#include <string>
#include <vector>

#include "globals.h"
#include "inputhandler.h"
#include "gameobjects.h"

int main()
{
	// Screen width
	screen_width = 1280;
	// Based on the screen width, we'll select a height that'll be 16:9
	screen_height = screen_width/16*9;

	// Create the window
	sf::RenderWindow window(sf::VideoMode(screen_width, screen_height), "Legacy");
	window.setFramerateLimit(60);

	// The Input Handler object
	inputHandler input;

	// Note: the below is just a test
	// This Vector will hold all our objects for this level
	vector<gameObjects> loadedObjects;
	loadGameObjects("resources/gameobjects/testobject.gob", loadedObjects, window);

	// Initialize all game objects
	for(int i = 0; i != loadedObjects.size(); i++)
	{
		// The reason we do this is because the last time
		// I tried to load the image->texture->sprite in
		// the loadGameObjects function, the sprite would
		// just lose the texture and become blank
		// So I'm assuming that the defined memory space
		// for the temporary object (that get spushed into
		// the vector) gets deleted when the function is
		// done and the temporary object(s) are destroyed.
		// So hence, us doing an init where we'll actually
		// be using the game objects, so they can re-assign
		// their textures and such
		gameObjects &selectedObject = loadedObjects[i];
		//selectedObject.printObjectVariables();
		selectedObject.init();
	}

	// While we haven't closed the window, do:
	while (window.isOpen())
	{
		// Check for input
		input.doInput(window);

		// Clear the window
		window.clear();

		// Think
		for(int i = 0; i != loadedObjects.size(); i++)
		{
			gameObjects &selectedObject = loadedObjects[i];
			selectedObject.think();
		}

		// Draw
		for(int i = 0; i != loadedObjects.size(); i++)
		{
			gameObjects &selectedObject = loadedObjects[i];
			window.draw(selectedObject.sprite);
		}

		// Display whatever we have drawn
		// to the window
		window.display();
	}

	return 0;
}